package component.model;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import model.Pegawai;

/**
 *
 * @author Marlon
 */
public class PegawaiTableModel extends DefaultTableModel{
    private List<Pegawai> listPegawai;
    private int listSize;
    
    public PegawaiTableModel(List<Pegawai> list){
        listPegawai = list;
        listSize = list.size();
    }

    @Override
    public int getColumnCount() {
        return 8;
    } 

    @Override
    public int getRowCount() {
        return listSize;
    }
    
    @Override
    public String getColumnName(int column) {
        switch(column) {
            case 0: return "NIP";
            case 1: return "Nama";
            case 2: return "Golongan";
            case 3: return "Jabatan";
            case 4: return "Tanggal Lahir";
            case 5: return "Agama";
            case 6: return "Tahun Masuk";
            case 7: return "Alamat";
            default: return "";
        }
    }
    
    @Override
    public Object getValueAt(int row, int column) {
        Pegawai pegawai = getPegawai(row);
        switch(column) {
            case 0: return pegawai.getNip();
            case 1: return pegawai.getNama();
            case 2: return pegawai.getGolongan();
            case 3: return pegawai.getJabatan();
            case 4: return pegawai.getTanggalLahir();
            case 5: return pegawai.getAgama();
            case 6: return pegawai.getTahunMasuk();
            case 7: return pegawai.getAlamat();
            default: return "";
        }
    }
    
    public Pegawai getPegawai(int row) {
        return listPegawai.get(row);
    }
}
